/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.faytechcc.csc251.gui;

import edu.faytechcc.csc251.db.MTGDBQuery;
import java.util.ArrayList;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author woodsk9710
 */
public class Model extends AbstractTableModel implements TableModelListener
                   
{
        private final String query;
        private final MTGDBQuery dbQuery;
        //private String[][] data;
        private final String[] colNames;
        private ArrayList<String[]> dataArrayList;
        
       
    public Model(String query)
    {
        this.query = query;
        dbQuery = new MTGDBQuery(this.query);
        
        //data = dbQuery.getData();
        
        dataArrayList = dbQuery.getList();
        
        colNames = dbQuery.getColumnNames();
    }
    @Override
    public int getRowCount()
    {
        return dataArrayList.size();
        //return data.length;
    }

    @Override
    public int getColumnCount()
    {
        return colNames.length;
    }

    @Override
    public Object getValueAt(int row, int col)
            
    {
        String[] array = dataArrayList.get(row);
        return array[col];
        //return data[row][col];
    }
    
 @Override
    public String getColumnName(int col) {
        return colNames[col];
    }
     
    public void setData(String data[][]){
        //this.data = data;
        fireTableDataChanged();
    }
    
//    public String[][] getData()
//    {
//        //return this.data;
//    }
    
    public ArrayList getDataArrayList()
    {
        return this.dataArrayList;
    }
    
    public String[] getColNames()
    {
        return this.colNames;
    }

    @Override
    public void tableChanged(TableModelEvent tme)
    {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void setDataList(ArrayList dataList) {
        this.dataArrayList = dataList;
        fireTableDataChanged();
    }
    
    
}
